//
//  TJUserData.swift
//  WeiBo
//
//  Created by TanJian on 15/12/9.
//  Copyright © 2015年 Joshpell. All rights reserved.
//

import UIKit

class TJUserData: NSObject {

    // 注意在 iPhone5 上,系统架构是32位,使用 int 系统会使用的是 int32 -> 微博id已经超出了
    
    var id: Int64 = 0
    
    // 微博的内容
    var text: String?
    
//     当前微博作者信息
    var user: TJUserInfo?
    // 微博的创建时间
    var created_at: String?
    // 来自
    var source: String?
    // 转发
    var reposts_count: Int = 0
    // 评论数
    var comments_count: Int = 0
    // 表态数
    var attitudes_count: Int = 0
    // 转发微博的内容
    var retweeted_status: TJUserData?
    // 当前微博的配图
    var pic_urls: [TJStatusPicInfo]?
    
    init(dict:[String:AnyObject]) {
        super.init()
        
        setValuesForKeysWithDictionary(dict)
    }
    
    
    override func setValue(value: AnyObject?, forKey key: String) {
        
        if key == "user" {
            if let dict = value as? [String:AnyObject]{
                user = TJUserInfo(dict: dict)
            }
        }else if key == "retweeted_status" {
            if let dict = value as? [String:AnyObject]{
            retweeted_status = TJUserData(dict: dict)
            }
        }else if key == "pic_urls"{
            
            if let array = value as? [[String:AnyObject]]{
                var tempArray = [TJStatusPicInfo]()
                
                //遍历字典转模型
                for dict in array {
                    tempArray.append(TJStatusPicInfo(dict: dict))
                }
                pic_urls = tempArray
            }
        }
        else{
            super.setValue(value, forKey: key)
        }
        
    }
    
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {}
    
    
    override var description:String{
        let keys = ["text", "retweeted_status","pic_urls"]
        return dictionaryWithValuesForKeys(keys).description
    }
    
}


